﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LBoL.Base;
using LBoL.ConfigData;
using LBoL.Core;
using LBoL.Core.Battle;
using LBoL.Core.Cards;
using LBoL.Core.StatusEffects;
using LBoLEntitySideloader.Attributes;
using ProbeMod.Cards.Template;

namespace ProbeMod.Cards
{
    public sealed class ProbeBlinkDef : ProbeCardTemplate
    {
        public override CardConfig MakeConfig()
        {
            var config = GetCardDefaultConfig();


            config.TargetType = TargetType.Nobody;
            config.Type = CardType.Defense;
            config.Rarity = Rarity.Common;

            config.Colors = new List<ManaColor>() { ManaColor.Blue };
            config.Cost = new ManaGroup() { Blue = 2, Any = 1 };
            config.UpgradedCost = new ManaGroup() { Blue = 1, Any = 1 };

            config.Block = 0;
            config.Shield = 0;
            
            config.Value1 = 2;  // 闪避层数

            config.Index = CardIndexGenerator.GetUniqueIndex(config);

            return config;
        }
    }

    /// <summary>
    /// 闪烁
    /// </summary>
    [EntityLogic(typeof(ProbeBlinkDef))]
    public sealed class ProbeBlink : ProbeCard
    {
        //public bool HasNoBlockOrShield
        //{
        //    get => Battle.Player.Block == 0 && Battle.Player.Shield == 0;
        //}

        public ManaGroup NoBlockMana
        {
            get => IsUpgraded ? new ManaGroup { Any = 1 } : new ManaGroup { Blue = 1, Any = 1 };
        }

        public override ManaGroup ForceCost 
        {
            get
            {
                return NoBlockMana;
            }
        } 

        public override bool Triggered => IsForceCost;

        public override bool IsForceCost
        {
            get
            {
                if (base.Battle != null)
                {
                    return  Battle.Player.Block == 0 && Battle.Player.Shield == 0 && !Battle.Player.HasStatusEffect<Graze>();
                }
                return false;
            }
        }

        protected override IEnumerable<BattleAction> Actions(UnitSelector selector, ManaGroup consumingMana, Interaction precondition)
        {
            yield return BuffAction<Graze>(base.Value1);
        }
    }
}
